﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TaskLib
{
    public partial class TaskListView : ListView
    {
        public const string DateColumnFormat = "ddd, MMM d, yy h:mm tt";

        protected int sortColumn;

        public TaskListView()
        {
            InitializeComponent();            
        }

        protected override void OnColumnClick(ColumnClickEventArgs e)
        {
            DoSort(e.Column);

            base.OnColumnClick(e);
        }

        private void DoSort(int column)
        {
            if (column != sortColumn)
            {
                sortColumn = column;
                Sorting = SortOrder.Ascending;
            }
            else
            {
                if (Sorting == SortOrder.Ascending)
                {
                    Sorting = SortOrder.Descending;
                }
                else
                {
                    Sorting = SortOrder.Ascending;
                }
            }

            // this does not seem to be necessary
            //Sort();

            this.ListViewItemSorter = new TaskListViewItemComparer(column, Sorting);
        }        
    }
}
